import defaultSettings from '@/settings';
import {
  getToken
} from '@/utils/auth';
import request from '@/utils/request';
import axios from 'axios';

/**
 * 上传文件获取token
 * @param {} data {}
 */
export function UploadGetToken() {
  return request.get('/system/upload/uploadToken');
}


/**
 * 上传图片
 * @param {File} data
 */
export function uploadImage(data) {
  var fd = new FormData();
  fd.append('file', data.file);
  return axios.post(defaultSettings.BASE_RUL + 'system/upload/img', fd, {
    headers: {
      'Content-Type': 'multipart/form-data',
      token: getToken()
    }
  });
}


// 删除
export function uploadImageDelete(fileName) {
  return axios.get(defaultSettings.BASE_RUL + 'system/upload/delete/' + fileName, {
    headers: {
      'Content-Type': 'multipart/form-data',
      token: getToken()
    }
  });
}


/**
 * 上传视频
 * @param {File} data
 */
export function uploadVideo(data) {
  var fd = new FormData();
  fd.append('file', data.file);
  return axios.post(defaultSettings.BASE_RUL + 'system/upload/video', fd, {
    headers: {
      'Content-Type': 'multipart/form-data',
      token: getToken()
    }
  });
}
/**
 * 上传多张图片
 * @param {File} data
 */
export function uploadImages(data) {
  var fd = new FormData();
  fd.append('files', data.file);
  return axios.post(defaultSettings.BASE_RUL + 'system/upload/images', fd, {
    headers: {
      'Content-Type': 'multipart/form-data',
      token: getToken()
    }
  });
}
